import { createStore } from 'vuex';

const store = createStore({
  state: {
    width: 200,
    Active: '/homePage',
  },
  mutations: {
    increment(state) {
      state.number++;
      localStorage.setItem('width', state.width);
    },
    restoreState(state) {
      const width = localStorage.getItem('width');
      if (width) {
        state.width = parseInt(width);
      }
    },
    resetActive(state, newNumber) {
      state.Active = newNumber
      localStorage.setItem('Active', state.Active);
    },

    
    getActive(state) {
      const Active = localStorage.getItem('Active');
      if (width) {
        state.width = parseInt(width);
      }
      localStorage.setItem('Active', state.Active);
    },
  }
});

// 在应用启动时调用 restoreState 恢复状态
store.commit('restoreState');

export default store;